﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace WPF_SFrost
{
    public partial class ConnectDB : Form
    {
        public ConnectDB()
        {
            InitializeComponent();
        }

        private void label1_Click(object sender, EventArgs e)
        {

        }

        private void button1_Click(object sender, EventArgs e)
        {
            //string connString = @"Data Source=.\SQLEXPRESS_10;Initial Catalog=AddressList;Integrated Security=True";
            string connString = @"Data Source=.\SQLEXPRESS_10;Initial Catalog=AddressList;uid = sa;pwd=97";
            SqlConnection conn = new SqlConnection();
            try
            {
                conn.ConnectionString = connString;
                conn.Open();
                MessageBox.Show("打开数据库连接成功。");
            }catch(Exception eX)
            {
                MessageBox.Show(eX.ToString());
            }
            finally
            {
                conn.Close();
                MessageBox.Show("关闭数据库连接成功。");
            }
        }
    }
}
